import React from 'react';
import { connect } from 'dva';
import ReactEcharts from 'echarts-for-react';
import echarts from 'echarts/lib/echarts';
import { Button } from 'antd';

// function AutomaticEcharts ({dataArr,xData,dataArr1,dataArr2,dataArr3,dataArr4,dataArr5,dataArr6,dataArr7,data,dispatch}){
class Average extends React.Component {
    constructor(props){
        super(props);
        this.state = {
          average:[]
        };

    }

    
    componentDidMount() {
        // 基于准备好的dom，初始化echarts实例
        const { dataArr,dataArr1,dataArr2,dataArr3,dataArr4,dataArr5,dataArr6,dataArr7 } = this.props;
        
        var myChart = echarts.init(document.getElementById('main'));
        function arrMaxNum(arr){
          return Math.max.apply(null,arr);
      }
      
      function arrMinNum(arr){
        return Math.min.apply(null,arr);
      }
      function arrAverageNum(arr){
          var sum = 0;
          for (var i = 0; i < arr.length; i++) {
              sum += arr[i];
          };
          return ~~(sum/arr.length*10000)/10000;
      }
       var average =[];
     

       average.push(arrAverageNum(dataArr));
       average.push(arrAverageNum(dataArr1));
       average.push(arrAverageNum(dataArr2));
      
       average.push(arrAverageNum(dataArr3));
     
       average.push(arrAverageNum(dataArr4));
     
       average.push(arrAverageNum(dataArr5));
     
       average.push(arrAverageNum(dataArr6));
      
      
       average.push(arrAverageNum(dataArr7));
     
      
        // 指定图表的配置项和数据
       
        var option = {
            title: {
                text: '各曲线平均值'
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                data: [ '各曲线平均值' ],
                width: 800,
                height: 700
            },
           
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    dataView: { show: true, readOnly: false },
                    // magicType : {show: true, type: ['line', 'bar']},
                    saveAsImage: {} //存取为图片
                }
            },
    
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data:["曲线1","曲线2","曲线3","曲线4","曲线5","曲线6","曲线7",]
            },
            yAxis: {
                type: 'value',
                // min: -0.13,
                // max: 0.04
            },
            // dataZoom: [
            // 	{
            // 		type: 'slider',
            // 		show: true,
            // 		start: 0,
            // 		end: 1,
            // 		handleSize: 1
            // 	}
            // ],
    
            series: [
                {
                    name: '曲线',
                    type: 'line',
                    stack: '总量',
                    data: average,
                    smooth: true
                },
    
                
            ]
      };
      
      
        myChart.setOption(option);
    
         
     
    }
  
    
    render() {
        return (
            <div>

                <div id="main" style={{ width: 1600, height: 700 }}></div>

            </div>

        );
    }
}
// export default LineMarkerEcharts;
export default connect(({ echart }) => ({ ...echart }))(Average)